package com.apartment.own.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.apartment.common.annotation.Log;
import com.apartment.common.core.controller.BaseController;
import com.apartment.common.core.domain.AjaxResult;
import com.apartment.common.enums.BusinessType;
import com.apartment.own.domain.OwnAccountInstallment;
import com.apartment.own.service.IOwnAccountInstallmentService;
import com.apartment.common.utils.poi.ExcelUtil;
import com.apartment.common.core.page.TableDataInfo;

/**
 * 账单分期Controller
 * 
 * @author @Dog_E
 * @date 2020-08-28
 */
@RestController
@RequestMapping("/own/installment")
public class OwnAccountInstallmentController extends BaseController
{
    @Autowired
    private IOwnAccountInstallmentService ownAccountInstallmentService;

    /**
     * 查询账单分期列表
     */
    @PreAuthorize("@ss.hasPermi('own:installment:list')")
    @GetMapping("/list")
    public TableDataInfo list(OwnAccountInstallment ownAccountInstallment)
    {
        startPage();
        List<OwnAccountInstallment> list = ownAccountInstallmentService.selectOwnAccountInstallmentList(ownAccountInstallment);
        return getDataTable(list);
    }

    /**
     * 导出账单分期列表
     */
    @PreAuthorize("@ss.hasPermi('own:installment:export')")
    @Log(title = "账单分期", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OwnAccountInstallment ownAccountInstallment)
    {
        List<OwnAccountInstallment> list = ownAccountInstallmentService.selectOwnAccountInstallmentList(ownAccountInstallment);
        ExcelUtil<OwnAccountInstallment> util = new ExcelUtil<OwnAccountInstallment>(OwnAccountInstallment.class);
        return util.exportExcel(list, "installment");
    }

    /**
     * 获取账单分期详细信息
     */
    @PreAuthorize("@ss.hasPermi('own:installment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ownAccountInstallmentService.selectOwnAccountInstallmentById(id));
    }

    /**
     * 新增账单分期
     */
    @PreAuthorize("@ss.hasPermi('own:installment:add')")
    @Log(title = "账单分期", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OwnAccountInstallment ownAccountInstallment)
    {
        return toAjax(ownAccountInstallmentService.insertOwnAccountInstallment(ownAccountInstallment));
    }

    /**
     * 修改账单分期
     */
    @PreAuthorize("@ss.hasPermi('own:installment:edit')")
    @Log(title = "账单分期", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OwnAccountInstallment ownAccountInstallment)
    {
        return toAjax(ownAccountInstallmentService.updateOwnAccountInstallment(ownAccountInstallment));
    }

    /**
     * 删除账单分期
     */
    @PreAuthorize("@ss.hasPermi('own:installment:remove')")
    @Log(title = "账单分期", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ownAccountInstallmentService.deleteOwnAccountInstallmentByIds(ids));
    }
}
